package letsjava.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class NSReflect{
	public static void main(String[] args) {
		try{
			
			System.out.println("Begin processing");
			Class<?> demo=null;
	        try{
	            demo=Class.forName("letsjava.utils.NSReflect");
	        }catch (Exception e) {
	            e.printStackTrace();
	        }
	        NSReflect per=null;
	        try {
	            per=(NSReflect)demo.newInstance();
	        } catch (InstantiationException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        } catch (IllegalAccessException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	        per.setName("Rollen");
	        per.setAge(20);
	        System.out.println(per);
	        
	        Method setAge=demo.getMethod("setAge", new Class[]{int.class}); 
	        setAge.invoke(per, 11);
	        System.out.println(per);
	        
	        Field age = demo.getField("age");
	        age.setAccessible(true);
	        age.setInt(per, 43);
	        System.out.println(per);
	
		}catch(Exception e){
			e.printStackTrace();
		}
	}
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public String toString(){
        return "["+this.name+"  "+this.age+"]";
    }
    private String name;
    public int age;
}
